package main

import (
	"fmt"
	"os/exec"
	"strings"
)

func main() {
	//执行sh命令
	cmd := exec.Command("/bin/bash", "-c", "/var/jenkins_home/workspace/getGitCommit.sh")
	//工作目录
	cmd.Dir = "."
	////获取返回值
	r, _ := cmd.Output()
	str := string(r)
	branchArray := strings.Split(str, "\n")
	if len(branchArray) > 0 {
		firstBranchInfo := branchArray[0]
		//获取到的信息示例：2023-02-08 13:37:05 +0800 21 hours ago  origin/copy_20230208
		start := strings.Index(firstBranchInfo, "origin")
		end := len(firstBranchInfo)
		firstBranchName := firstBranchInfo[start:end]
		fmt.Print(firstBranchName)
	}
}
